package main

import (
	_ "supershare/backend/models" // 确保models包被初始化
	_ "supershare/backend/routers"
	"supershare/backend/tasks"
	_ "supershare/backend/tasks"

	"github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/server/web/filter/cors"
	"github.com/beego/beego/v2/task"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	// 允许跨域请求
	web.InsertFilter("*", web.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "AppId", "Access-Control-Allow-Origin", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin"},
		AllowCredentials: true,
	}))
	tasks.InitOrderTasks()
	task.StartTask()
	defer task.StopTask()

	// 启动beego应用
	web.Run()
}
